{% extends 'base/base.html' %}
{% load myinclusion %}
{% block stylesheets %}
    {{ block.super }}
    <link href="/static/others/css/bootstrapValidator.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/vendors/bootstrap-select/css/bootstrap-select.min.css">
{% endblock %}
{% block content %}
    <div class="right_col" role="main">
        <div class="">
            <div class="clearfix"></div>

            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="tabbable" id="tabs-754998">

                        <div class="x_panel" style="border-top:none;">
                            <div class="x_title">
                                <h2>文件管理 </h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                           aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                        <ul class="dropdown-menu" role="menu">
                                            <li><a href="#">Settings 1</a>
                                            </li>
                                            <li><a href="#">Settings 2</a>
                                            </li>
                                        </ul>
                                    </li>
                                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <div class="loading"></div>

                                <div class="tab-content">
                                    <div class="tab-pane active" id="panel-single">
                                        <form class="form-horizontal form-border" enctype="multipart/form-data"
                                              id="id_form">
                                            {% csrf_token %}
                                            {% if perms.deploy.edit_fileupload %}
                                                <fieldset>
                                            {% else %}
                                                <fieldset disabled="disabled">
                                            {% endif %}
                                            <div class="item form-group">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12">目标主机 <span
                                                        class="required">*</span>
                                                </label>
                                                <div class="col-md-6 col-sm-6 col-xs-12 form-group">
                                                    <select id="id_tgt_select" name="id_tgt_select[]"
                                                            class=" selectpicker show-menu-arrow form-control"
                                                            data-selected-text-format="count" multiple
                                                            data-live-search="true">
                                                        {% for item in tgt_list %}
                                                            <option value="{{ item.nodename }}">
                                                                {{ item.nodename }}</option>
                                                        {% endfor %}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                       for="first-name">远程路径<span class="required">*</span>
                                                </label>
                                                <div class="col-md-6 col-sm-6 col-xs-12">
                                                    <input type="text" id="first-name" required="required"
                                                           class="form-control col-md-7 col-xs-12">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                       for="id_file_path">选择文件<span class="required">*</span>
                                                </label>
                                                <div class="col-md-6 col-sm-6 col-xs-12">
                                                    <input class="form-control col-md-7 col-xs-12" id="id_file_path"
                                                           name="file_path" type="file"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                       for="last-name">备注<span class="required">*</span>
                                                </label>
                                                <div class="col-md-6 col-sm-6 col-xs-12">
                                                    <input type="text" id="last-name" name="last-name"
                                                           required="required" class="form-control col-md-7 col-xs-12">
                                                </div>
                                            </div>

                                            <div class="item form-group">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12">返回结果
                                                </label>
                                                <div class="col-md-6 col-sm-6 col-xs-12">
                                                    <textarea class="form-control" name="result"
                                                              rows="10">{{ ret }}</textarea>
                                                </div>
                                            </div>
                                            <div class="ln_solid"></div>
                                            <div class="form-group">
                                                <div class="col-md-6 col-md-offset-3">
                                                    <input type="submit" name="send" class="btn btn-success" value="提交">
                                                </div>
                                            </div>
                                            </fieldset>
                                        </form>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" class="form-control" value="" id="jid">
                    <input type="hidden" class="form-control" value="" id="exec_type">

                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javascripts %}
    {{ block.super }}
    <script src="/static/others/js/bootstrapValidator.min.js"></script>
    <script src="/static/vendors/bootstrap-select/js/bootstrap-select.min.js"></script>
    <script>

        $(document).ready(function () {

            $('.selectpicker').selectpicker({
                noneSelectedText: '======请选择=====' //默认显示内容
            });

            $("#id_form").bootstrapValidator({
                fields: {
                    tgt_select: {
                        validators: {
                            notEmpty: {
                                message: '请选择主机'
                            }
                        }
                    },
                    remote_path: {
                        validators: {
                            notEmpty: {
                                message: '请填写远程路径'
                            }
                        }
                    },
                    file_path: {
                        validators: {
                            notEmpty: {
                                message: '请选择文件'
                            },
                            file: {
                                extension: 'zip,gz,bz2,sls,txt,html,conf,lua,sh,py',
                                message: '不支持该类型文件上传'
                            }
                        }
                    }
                }
            })

        });


        {% comment %}$(function () {
            $("#panel-group select[name='tgt_select']").bind("change", function () {
                var tgt_select = $("#panel-group select[name='tgt_select']").val();
                if (tgt_select != "") {
                    $.ajax({
                        type: "POST",
                        url: "{% url 'ajax_minions' %}",
                        data: {tgt_select: tgt_select},
                        dataType: "html",
                        success: function (ret) {
                            var ret = eval('(' + ret + ')');
                            var html = "<label class=\"control-label col-md-3 col-sm-3 col-xs-12\">包含主机</label><div class=\"col-md-6 col-sm-6 col-xs-12\"><fieldset disabled><textarea class=\"form-control\">" + ret + "</textarea></fieldset></div>";
                            $("#panel-group div[name='group_minions']").html(html);
                        }
                    })
                } else {
                    $("#panel-group div[name='group_minions']").html("");
                }
            })
        }){% endcomment %}
    </script>
{% endblock %}
